<?php
/**
 * Created by PhpStorm.
 * User: Hongjw
 * Date: 2018/3/13
 * Time: 18:15
 */

namespace App\Http\Controllers\Laravel\Response;


use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;

class BackController extends Controller
{
    public $home = '/laravel/response/back/';
    public function showIndex(Request $request){
        $class = new \ReflectionClass(static::class);
        $arr = $class->getMethods();
        //dd($arr);
        $url = url($this->home);
        foreach ($arr as $value){
            echo "<a href='$url/$value->name'>$value->name</a><br>";
        }

        $errors = Session::get('errors');
        if($errors){
            //if($errors->hasBag('errors123')){
                dump($errors->getBag('errors123')->all());
            //}
        }



        dump(Session::all());
        //使用Input::old 和 old()函数都调用不到 back()->with()设置参数
        dump(Input::old('where?'));
        dump(Input::old('test'));
        dump(old('test'));
        dump($request->old('where?'));
        return view('admin.errors');
        dd(Session::all());

    }
    public function myWithErrors(){
        return back()->withErrors(['hello','123'],'errors123')->withErrors(['???','!!!']);
    }

    public function myWith(Request $request){
        if(old('where?')){
            dd("old()");
        }
        if(Input::old('where?')){
            dd("Input");
        }
        if($request->old('where?')){
            dd('$request');
        }
        /**
         * with只能通过key值取了
         */
        return back()->with('where?','yes');
    }

    public function myWithInput(Request $request){
        return back()->withInput();
    }

    public function myView(){

    }

}